/*
 * @Descripttion: 
 * @version: 
 * @Author: Eugene
 * @Date: 2024-06-29 17:49:43
 * @LastEditors: Andy
 * @LastEditTime: 2024-07-05 15:30:45
 */
#ifndef __WHW_MOTOR_H
#define __WHW_MOTOR_H

#include "RUI_MATH.h"
#include "pid.h"
#include "FFC.h"
#include "MY_define.h"

typedef struct
{
    int8_t ONLINE_JUDGE_TIME;
    int16_t Angle_last; // 上一个角度值
    int16_t Angle_now;  // 现在的角度值
    int16_t Speed_last; // 上一个速度值
    int16_t Speed_now;  // 现在的速度值
    int16_t current;
    int8_t temperature;
    int32_t Angle_Infinite;
    uint16_t Stuck_Time;
    uint16_t Stuck_Flag[2];
    int16_t Laps;
    float Error;
    float Aim;
    float Aim_last;
    float dt;
}WHW_MOTOR_DATA_Typedef;

typedef struct
{
    uint8_t PID_INIT;
    WHW_MOTOR_DATA_Typedef DATA;
    Feedforward_t PID_F;
    pid_type_def PID_P;
    pid_type_def PID_S;
}WHW_MOTOR_Typedef;

extern WHW_MOTOR_Typedef WHW_MOTOR_Pitch;
extern WHW_MOTOR_Typedef WHW_MOTOR_Roll;

uint8_t WHW_MOTER_Init(void);
void RUI_F_MOTOR_CAN_RX_3508RM_WITHOUT_ANGLE(WHW_MOTOR_Typedef* MOTOR , uint8_t* can_data);
void RUI_F_MOTOR_CAN_RX_3508RM(WHW_MOTOR_Typedef* MOTOR , uint8_t* can_data);
void RUI_F_MOTOR_CAN_RX_2006RM(WHW_MOTOR_Typedef* MOTOR , uint8_t* can_data);
void RUI_F_HEAD_MOTOR_CLEAR(WHW_MOTOR_Typedef* MOTOR , uint8_t mode);
void RUI_F_HEAD_MOTOR2006_STUCK(WHW_MOTOR_Typedef* MOTOR , uint16_t ERROR_ANGLE , uint16_t ERROR_SPEED , uint16_t ERROR_TIME);
void RUI_F_HEAD_MOTOR3508_STUCK(WHW_MOTOR_Typedef* MOTOR , uint16_t ERROR_CURRENT , uint16_t ERROR_SPEED);
void RUI_F_HEAD_MOTOR6020_STUCK(WHW_MOTOR_Typedef* MOTOR , uint16_t ERROR_ANGLE , uint16_t ERROR_SPEED , uint16_t ERROR_TIME);


#endif
